﻿var winState = "0";

Ext.onReady(function () {
    yeardata = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetYearTime'),
        root: 'ResponseObject',
        fields: ['yearid', 'yeartext'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    yeardata.load();
    //数据列表
    var lmsstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('SecurityMarket.EverydayRisksView', 'GetReport'),
        root: 'ResponseObject',
        fields: ['被检部门', '地理位置', '隐患级别', '隐患类别', '隐患内容', '隐患内容备注', '检查时间', '检查人', '整改措施', '三定时间', '制单人', '制单日期', '负责人', '处理时间', '复查人', '复查时间', '状态'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.year = Ext.getCmp("year").getValue();
                re.params.month = Ext.getCmp("month").getValue();
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });

    function dateFormat(s, m) {

        if (s == null || s == '') return '';
        var start = s.indexOf('(');
        var end = s.indexOf('+');
        var temp = s.substring(start + 1, end);
        return (new Date(parseInt(temp))).format('Y-m-d');
    }

    var lmsdatagrid = new Ext.grid.GridPanel({
        autoscroll: true,
        bodyStyle: 'padding:2px',
        border: false,
        loadMask: true, //加载
        viewConfig: {
            getRowClass: function (record, rowIndex, rp, ds) {
                if (record.get('状态') == '新隐患') {
                    return 'redNum';
                }
                else if (record.get('状态') == '正在处理') {
                    return 'yellowNum';
                }
                else {
                    return 'GreenNum';
                }
            }
        },
        columns: [
           { id: '被检部门', header: '被检部门', width: 100, dataIndex: '被检部门', sortable: true },
           { header: '地理位置', width: 100, dataIndex: '地理位置', sortable: true },
           { header: '隐患级别', width: 100, dataIndex: '隐患级别', sortable: true },
           { header: '隐患类别', width: 100, dataIndex: '隐患类别', sortable: true },
           { id: '隐患内容', header: '隐患内容', width: 100, dataIndex: '隐患内容', sortable: true },
           { id: '隐患内容备注', header: '隐患内容备注', width: 100, dataIndex: '隐患内容备注', sortable: true },
           { id: '检查时间', header: '检查时间', width: 100, dataIndex: '检查时间', sortable: true, renderer: dateFormat },
           { id: '检查人', header: '检查人', width: 100, dataIndex: '检查人', sortable: true },
           { id: '整改措施', header: '整改措施', width: 100, dataIndex: '整改措施', sortable: true },
           { id: '三定时间', header: '三定时间', width: 100, dataIndex: '三定时间', sortable: true, renderer: dateFormat },
           { id: '制单人', header: '制单人', width: 100, dataIndex: '制单人', sortable: true },
           { id: '制单日期', header: '制单日期', width: 100, dataIndex: '制单日期', sortable: true, renderer: dateFormat },
           { id: '负责人', header: '负责人', width: 100, dataIndex: '负责人', sortable: true },
           { id: '处理时间', header: '处理时间', width: 100, dataIndex: '处理时间', sortable: true, renderer: dateFormat },
           { id: '复查人', header: '复查人', width: 100, dataIndex: '复查人', sortable: true },
           { id: '复查时间', header: '复查时间', width: 100, dataIndex: '复查时间', sortable: true, renderer: dateFormat },
           { id: '状态', header: '状态', width: 100, dataIndex: '状态', sortable: true }
   ],
        store: lmsstore
    });
    //布局
    new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            layout: 'fit',
            border: false,
            title: '团柏矿安全市场报表',
            iconCls: 'ReportTitle-icon',
            tbar: ['日期：', { xtype: 'combo', width: 100, id: 'year',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: yeardata,
                valueField: 'yearid',
                displayField: 'yeartext'
            }, '年', { xtype: 'combo', width: 70, id: 'month',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: new Ext.data.ArrayStore({
                    id: 0,
                    fields: [
                            'monthid',
                            'monthtext'
                        ],
                    data: [['01', '01'], ['02', '02'], ['03', '03'], ['04', '04'], ['05', '05'], ['06', '06'], ['07', '07'], ['08', '08'], ['09', '09'], ['10', '10'], ['11', '11'], ['12', '12']]
                }),
                valueField: 'monthid',
                displayField: 'monthtext'
            }, '月', { xtype: 'button', text: '查询', iconCls: 'search-icon', handler: function () {
                lmsstore.removeAll();
                lmsstore.load();
            }
            }, '->', '-',

        { xtype: 'button', text: '被检部门', iconCls: 'bjbm-icon', handler: function () { window.open('SecurityMarket/DepartmentsChart.aspx') } },
        { xtype: 'button', text: '地理位置', iconCls: 'dlwz-icon', handler: function () { window.open('SecurityMarket/LocationChart.aspx') } },
        { xtype: 'button', text: '隐患类别', iconCls: 'yhlb-icon', handler: function () { window.open('SecurityMarket/HazardTypesChart.aspx') } },
        { xtype: 'button', text: '隐患等级', iconCls: 'yhdj-icon', handler: function () { window.open('SecurityMarket/HazardLevelChart.aspx') } },

         '-', { xtype: 'textfield', border: false, readOnly: true, width: 40, height: 20, style: 'background:#B2001F' }, '新隐患',
         { xtype: 'textfield', border: false, readOnly: true, width: 40, height: 20, style: 'background:#F1AF00' }, '正在处理',
         { xtype: 'textfield', border: false, readOnly: true, width: 40, height: 20, style: 'background:Green' }, '已复查',
         { xtype: 'button', text: '返回', height: 20, width: 50, iconCls: 'page-back-icon', handler: function () { window.history.back(-1); } }
        ],
            items: [{
                region: 'center',
                title: '数据报表',
                iconCls: 'DataList-icon',
                style: 'padding:2px',
                collapsible: false,

                split: false,
                id: 'DataList',
                layout: 'fit',
                items: lmsdatagrid
            }]
        }],
        listeners: {
            render: function () {
                Ext.getCmp("year").setValue(YearT);
                Ext.getCmp("month").setValue(MonthT);
                lmsstore.load();
            }
        }
    })
});


